package ar.edu.uba.fi.jmit.monitorengine.backend.client.view;

import ar.edu.uba.fi.jmit.monitorengine.backend.client.Monitorengine;
import ar.edu.uba.fi.jmit.monitorengine.backend.client.controller.MenuController;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;

public class MenuPanel extends VerticalPanel implements ValueChangeHandler<String> {
	
	private MenuController menuController;
	
	public MenuPanel(Monitorengine monitorengine) {
		super();
		this.menuController = new MenuController(monitorengine);
	}

	@Override
	protected void onLoad() {
		GWT.log("MenuPanel loaded");
		super.onLoad();
		this.add(new Hyperlink("Last Received Messages", "menu-receivedMessages"));
		this.add(new Hyperlink("Loaded Files", "menu-loadedFiles"));
		this.add(new Hyperlink("Visualizers", "menu-visualizers"));
		this.add(new Hyperlink("Receiver Stats", "menu-receiverStats"));
		this.add(new Hyperlink("Upload File", "menu-fileupload"));
		//this.add(new Hyperlink("Users", "menu-users"));
		History.addValueChangeHandler(this);
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		GWT.log("The value change event is " + event.getValue());
		if(!event.getValue().startsWith("menu-")) {
			GWT.log("Not a Menu event, discarging it");
			return;
		}
		if("menu-receivedMessages".equals(event.getValue())) {
			menuController.onReceivedMessagesLink();
		}
		if("menu-loadedFiles".equals(event.getValue())) {
			menuController.onLoadedFilesLink();
		}
		if("menu-visualizers".equals(event.getValue())) {
			menuController.onVisualizersLink();
		}
		if("menu-receiverStats".equals(event.getValue())) {
			menuController.onReceiverStatsLink();
		}
		if("menu-fileupload".equals(event.getValue())) {
			menuController.onFileUploadLink();
		}
	}

}
